<template>
  <div>
    <p-modal
      :title="title"
      :visible="visible"
      :confirm-loading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
    >
      <p-form-model
        ref="ruleForm"
        :model="form"
        :rules="rules"
        :label-col="labelCol"
        :wrapper-col="wrapperCol"
      >
        <p-form-model-item ref="warnValue" label="警戒值" prop="warnValue">
          <p-input-number
            id="inputNumber"
            :min = "1"
            v-model="form.warnValue"
            @blur="
              () => {
                $refs.warnValue.onFieldBlur();
              }
            "
          />
        </p-form-model-item>
      </p-form-model>
    </p-modal>
  </div>
</template>
<script>
import { putAction, getAction } from "@/api/manage";

export default {
  props:{
    warnValue:{
      type: Number,
      required: true,
      default: 0
    }
  },
  data() {
    return {
      ModalText: "Content of the modal",
      visible: false,
      confirmLoading: false,
      labelCol: { span: 4 },
      wrapperCol: { span: 14 },
      other: "",
      form: {
        warnValue: this.warnValue,
      },
      rules: {
        warnValue: [
          { required: true, message: "警戒值不能为空", trigger: "blur" },
        ],
      },
      url: {
        get: "",
        put: "/mes-code/mesBcMacAddress/warnValue",
      },
    };
  },

  methods: {
    showModal(title) {
      this.visible = true;
      this.title = title;
      this.form.warnValue = this.warnValue
    },
    handleOk(e) {
      this.ModalText = "The modal will be closed after two seconds";
      this.confirmLoading = true;
      putAction(this.url.put, this.form).then((res) => {
        if (res.success) {
          this.$message.success("处理完成!");
        } else {
          this.$message.warning("处理失败!");
        }
        this.visible = false;
        this.confirmLoading = false;
        this.$emit('getWarnValue', '')
      });
    },
    handleCancel(e) {
      console.log("Clicked cancel button");
      this.visible = false;
    },

    onSubmit() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm() {
      this.$refs.ruleForm.resetFields();
    },
  },
};
</script>